package mini.ideashare.cms.manager;

import mini.ideashare.cms.dao.TB_ItemDAO;
import mini.ideashare.cms.model.TB_Item;
import mini.ideashare.cms.model.qc.TB_ItemQC;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * @Author lixiang
 * @CreateTime 2018/10/27
 **/
@Component
public class JobManager {

    private Logger logger = LoggerFactory.getLogger(JobManager.class);

    @Autowired
    private TB_ItemDAO itemDAO;


    //每天早上0.00开始跑定时任务
    @Scheduled(cron = "0 1 0 * * *")
    public void removeExpire(){
        TB_ItemQC qc = new TB_ItemQC();
        qc.setExpireTime(new Date());
        List<TB_Item> tb_items = itemDAO.listTB_Item(qc);
        logger.info("任务开始执行，需要删除的数据有{}条",tb_items.size());
        for (TB_Item tb_item : tb_items) {
            itemDAO.deleteTB_ItemById(tb_item.getId());
        }
    }
}
